$(function(){
     //个人资料
    $(".head .avatar").on("click",function(){
        window.location.href="my_personalInfo.html";
    })
    
    //我的客服
    $("#customerService").on("click",function(){
        window.location.href="my_customerService.html";
    })
    // 退出登录
    $("#exitLogon").on("click",function(){
        $(".mask .tip").html("是否确定退出？");
        $(".mask").show();
        var btn=document.querySelector(".mask .btn");
        var mask=document.querySelector(".mask");
        btn.onclick=function(){
            window.localStorage.clear("appUserInfo");
            mask.style.display="none";
            window.location.href="../homePage.html";
        }
        
    })

    init();
})
/**
 * 页面初始化
 */
function init(){
    $(".loding").show(0);
    var userData=baseFunction.getUserInfo();
    var data =JSON.parse(userData);
    // dom操作
    var name=(JSON.parse(data.user)).trueName ? (JSON.parse(data.user)).trueName : (JSON.parse(data.user)).loginName; //昵称
    var phone=(JSON.parse(data.user)).loginName; //登录返回的用户名
    $(".head .phone").html(name);
    getUserInfo(phone); //获取银行卡
    getReferee(phone);


    // 银行卡管理
    $("#bankCardMG").on("click",function(){
        baseFunction.verifyingRealName(function(){
            window.location.href="my_bankCardMG.html?loginName="+phone+"";
        }) 
    })
    //会员管理
    $("#memberManage").on("click",function(){
        window.location.href="my_memberManage.html?loginName="+phone+"";
    })
    //密码管理
    $("#passwordManage").on("click",function(){
        window.location.href="my_passwordManage.html?loginName="+phone+"";
    })
    // 推荐人
    $("#myRecommender").on("click",function(){
        window.location.href="my_myRecommender.html?loginName="+phone+"";
    })
    // 更换结算卡
    $("#bankCardInfo").on("click",function(){
        baseFunction.verifyingRealName(function(){
            window.location.href="my_bankCardInfo.html?loginName="+phone+"";
        }) 
       
    })
    // 常见问题
    $("#commonProblem").click(function(){
        window.location.href=httpUrl+"branchHelp.do?method=initTitle&branchno=" + branchno + "&type=1"
    })
}
/**
 * 获取用户信息
 */
function  getUserInfo (phone){
    var data={
      userName: baseFunction.encryption(phone),
      queryType:"4610"
    }
    baseFunction.netRequest("param",data,function(res){
        $(".loding").hide(0);
         //解密
        if (res.code==200){
            var data = JSON.parse(JSON.parse(res.data).result);
            $("#bankCardMG .left>p").html(data.cardCount+"张"); //银行卡的张数
            var gradeImg=data.saleLevel==3?"../static/img/profile_top_gold.png":"../static/img/profile_top_bronze.png";//用户等级
            $(".content .head .grade").attr("src",gradeImg); 
        }else{
            $(".prompt").html(res.message).show(0).delay(1000).hide(0);
        }
    })
}
/**
 * 获取推荐人信息
 */
function  getReferee(phone){
    var data={
      userName: baseFunction.encryption(phone),
      queryType:"4411"
    }
    baseFunction.netRequest("param",data,function(res){
         //解密
        if(res.code==200){
            $("#myRecommender .left p").html(JSON.parse(JSON.parse(res.data).result).trueName);
        }
    })
}